using System;
using System.Configuration;

namespace KodeIT.Web.Configuration
{
    public sealed class HttpFiltersSection : ConfigurationSection
    {
        #region Constants

        internal const string PROPERTY_ERROR_DETAIL = "errorDetail";
        internal const string PROPERTY_ERROR_PAGE = "errorPage";

        #endregion

        #region Statics

        internal static string FiltersSectionName = "httpFilters";

        private static ConfigurationProperty _propFilters;
        private static ConfigurationProperty _propErrorDetail;
        private static ConfigurationProperty _propErrorPage;
        private static readonly ConfigurationPropertyCollection _properties;

        static HttpFiltersSection()
        {
            _propFilters = new ConfigurationProperty(
                null, typeof(HttpFilterCollection), null, ConfigurationPropertyOptions.IsDefaultCollection);

            _propErrorDetail = new ConfigurationProperty(
                PROPERTY_ERROR_DETAIL, typeof(ErrorDetail), ErrorDetail.LocalOnly, ConfigurationPropertyOptions.None);

            _propErrorPage = new ConfigurationProperty(
                PROPERTY_ERROR_PAGE, typeof(string), null, ConfigurationPropertyOptions.None);

            _properties = new ConfigurationPropertyCollection();
            _properties.Add(_propFilters);
            _properties.Add(_propErrorDetail);
            _properties.Add(_propErrorPage);
        }
        #endregion

        #region Properties

        [ConfigurationProperty("", IsDefaultCollection = true)]
        public HttpFilterCollection Filters
        {
            get { return (HttpFilterCollection)base[_propFilters]; }
        }

        [ConfigurationProperty(PROPERTY_ERROR_DETAIL, DefaultValue = ErrorDetail.LocalOnly, IsRequired = false)]
        public ErrorDetail ErrorDetail
        {
            get { return (ErrorDetail)base[_propErrorDetail]; }
            set { base[_propErrorDetail] = value; }
        }

        [ConfigurationProperty(PROPERTY_ERROR_PAGE, DefaultValue = null, IsRequired = false)]
        public string ErrorPage
        {
            get { return (string)base[_propErrorPage]; }
            set { base[_propErrorPage] = value; }
        }

        #endregion
    }
}
